package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 二手车服务费
 */
@Component
public class UsedCarServeFeeExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate){

        return " SELECT X.CREATE_DATE, " +
                "             '二手车' " +
                "                                                                             INCOME_CATEGORIES, " +
                "             '二手车服务费'                                                        SERVE_TYPE_NAME, " +
                "             X.DEPT_ID, " +
                "             X.COMPANY_ID, " +
                "             SUM(X.STORE_PRICE)                                              AMOUNT, " +
                "             0                                                               TIMES, " +
                "             SUM(X.STORE_PRICE)                                              PRICE_TOTAL, " +
                "             0                                                               COST, " +
                "             0                                                               CONSUMABLE_USE," +
                "0 vip_in,0 vip_out, " +
                "             0                                                               ACCESSORY_COST, " +
                "             0                                                               MAN_HOUR_COST, " +
                "             SUM(X.PLATFORM_MANAGEMENT_FEE)                                  PLATFORM_MANAGEMENT_FEE, " +
                "             0                                                               SUPPLY_CHAIN_MANAGEMENT_FEE " +
                "      FROM (SELECT TRUNC(A.DATE_APPROVE) " +
                "                       CREATE_DATE, " +
                "                   A.DEPT_ID, " +
                "                   A.COMPANY_ID, " +
                "                   A.STORE_PRICE, " +
                "                   A.PLATFORM_MANAGEMENT_FEE " +
                "            FROM WAR_USED_CAR A " +
                "            WHERE A.DATE_APPROVE IS NOT NULL " +
                "              AND A.DATE_APPROVE >= to_date(:P_DATE, 'YYYY-mm-dd') " +
                "              AND A.DATE_APPROVE < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X " +
                "      GROUP BY X.CREATE_DATE, X.DEPT_ID, " +
                "               X.COMPANY_ID";
    }

    @Override
    public boolean support(String type) {
        return "UsedCarServeFee".equals(type);
    }
}
